package com.algo.moduleSix;

import java.util.Arrays;

public class FindNumberOfLIS {

    public int findNumberOfLIS(int[] nums) {
        int n = nums.length;
        // 最长子序列
        int[] dp = new int[n];
        // 最长子序列个数
        int[] count = new int[n];
        int maxLength = 0;
        // 初始化 1
        Arrays.fill(dp, 1);
        Arrays.fill(count, 1);
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= i; j++){
                if(nums[j]< nums[i]){
                    if(dp[j]+1 > dp[i]){
                        dp[i] = dp[j]+1;
                        count[i] = count[j];
                    }else if (dp[j]+1 == dp[i]){

                        count[i] += count[j];
                    }
                }
            }
            maxLength = Math.max(maxLength, dp[i]);
        }
        int ans = 0;
        for(int i =0; i< n; i++){
            if(dp[i] == maxLength){
                ans += count[i];
            }

        }

        return ans;
    }
}
